<template>
	<el-form ref="form" :model="form" label-width="50px" class="form">
		<el-form-item label="帐号">
			<el-input v-model="form.username"></el-input>
		</el-form-item>
		<el-form-item label="密码">
			 <el-input v-model="form.password" type="password"></el-input>
		</el-form-item>
    	<el-button type="primary" size="large" @click="login()">登录</el-button>
	    <div class="go_register">
	    	<p>不是会员?<router-link to="register" replace><el-button type="text">去注册</el-button></router-link></p>
	    </div>
	    <el-dialog
		  title="提示"
		  :visible.sync="dialogVisible"
		  size="tiny"
		>
		  <span>登录成功！{{this.hasVerify == -1 ? '你还没有实名认证' : ''}}</span>
		  <span slot="footer" class="dialog-footer">
		  	<router-link :to="{name:'home'}" replace>
		    	<el-button >去首页</el-button>
		    </router-link>
		    <router-link :to="{name:'verify'}" replace v-if="this.hasVerify == -1">
		    	<el-button type="primary">实名认证</el-button>
		    </router-link>	   	    
		  </span>
	    </el-dialog>
	</el-form>
</template>
<script type="text/javascript">
export default {
	data() {
		return {
			form: {
		        username: '',
		        password: ''
        	},
        	hasVerify: -1,
        	dialogVisible: false,
		}
	},
	methods: {
		login: function(){
			console.log(this.form);
			this.$http({
			  method: 'post',
			  url: '/log/login',
			  data: this.form
			}).then((response)=>{
				const { data } = response;
			    if(data.status === 'SUCCESS'){
			    	this.dialogVisible = true;
			    	this.hasVerify = data.object.type;
			    	console.log(window.sessionStorage)
					window.sessionStorage.setItem('user',JSON.stringify(data.object));
			    }else {
			    	this.$message({
			          message: data.message
			        });
			    }
			})
			.catch(function (error) {
			   console.log(error);
			});
		}
	}
}
</script>
<style scoped>
	.form {
		width: 400px;
		margin: 100px auto 50px auto;
		z-index: 2;
		text-align: center;
	}
    .go_register {
    	margin: 30px;
    }
</style>